var Main = {
    data() {
        return {
            ruleForm: {
                Username: '',
                Password: '',
                Code:'',
            },
            key:origin_key,
            img:origin_captcha,
            rules: {
                Username: [
                    { required: true, message: '请输入账号', trigger: 'blur' },
                    { min: 2, message: '长度不能少于 2 个字符', trigger: 'blur' }
                ],
                Password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 6, message: '长度不能少于 6 个字符', trigger: 'blur' }
                ],
                Code: [
                    { required: true, message: '请输入验证码', trigger: 'blur' },
                ],
            }
        };
    },
    methods: {
        /**
         *
         * @param formName
         * @param key 验证码key
         */
        submitForm(formName,key) {
            this.$refs[formName].validate((valid) => {
                if (!valid) {
                    return
                }
                let _this = this
                var regData = _this.ruleForm
                regData.Key = key
                axios.post('register', regData)
                    .then(res => {
                        var res_code = res.data.code
                        if (res_code === 200) {
                            this.$message({
                                showClose: true,
                                message: '注册成功',
                                type: 'success'
                            })
                            location.href = "login"
                        } else {
                            this.$message({
                                showClose: true,
                                message: ginConfig[res_code],
                                type: 'error'
                            })
                        }
                    })
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        captcha() {
            var vm = this;
            axios.get('captcha', {})
                .then(res => {
                    vm.img = res.data.captcha
                    vm.key = res.data.idkey
                })
        },
    }
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')